package com.arpa.wms.common.util;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * UUID工具类
 */
public class UUIDUtil implements Serializable {
    private static final long serialVersionUID = -741325524978030957L;
    private static final String YYYY_MM_DD_HH_MM_SS = "yyyyMMddHHmmss";

    private UUIDUtil() {
        throw new IllegalStateException("Utility class");
    }

    /**
     * 获取36个字符长度的UUID
     *
     * @return
     */
    public static String getUUID36() {
        return UUID.randomUUID().toString();
    }

    /**
     * 获取32个字符长度的UUID
     *
     * @return
     */
    public static String getUUID32() {
        String uuid = getUUID36();
        return uuid.replaceAll("-", "");
    }

    public static String getVerificationCode(int len) {
        Random r = new Random();
        String num = "";
        for (int i = 0; i < len; i++) {
            num += r.nextInt(10);
        }
        return num;
    }

    /**
     * 获取当前时间+5位随机数
     *
     * @return
     */
    public static String getTimeRandom() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        Date date = new Date();
        String str = simpleDateFormat.format(date);
        Random random = new Random();
        // 获取5位随机数
        int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;
        return str + rannum;
    }


    /**
     * 生成货物条形码规则
     * 当前时间+手机号后四位+4位随机数
     *
     * @return
     */
    public static String getQrCode() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        Date date = new Date();
        String str = simpleDateFormat.format(date);
        Random random = new Random();
        // 获取4位随机数
        int rannum = (int) (random.nextDouble() * (9999 - 1000 + 1)) + 1000;
        return str + rannum;
    }

    /**
     * 生成单号规则
     * 前缀+当前时间+4位随机数
     *
     * @return
     */
    public static String getOrderSN(String prefix) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        Date date = new Date();
        String str = simpleDateFormat.format(date);
        Random random = new Random();
        // 获取4位随机数
        int rannum = (int) (random.nextDouble() * (9999 - 1000 + 1)) + 1000;
        return prefix + str + rannum;
    }

    public static String getOrderInComeCode() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        Date date = new Date();
        String str = simpleDateFormat.format(date);
        Random random = new Random();
        // 获取4位随机数
        int rannum = (int) (random.nextDouble() * (9999 - 1000 + 1)) + 1000;
        return str + rannum;
    }

}
